<template>
<div>
      <div>
            <h2>账户余额</h2>
            {{userAmount}}
            {{totalPrice}}
      </div>
      <div>
          <el-button type="danger" round>余额支付</el-button>
          <el-button type="danger"@click="wxpayimg=true" round>微信支付</el-button>
          <el-button type="danger"@click="alipay" round>支付宝支付</el-button>
      </div>
      <div v-if="wxpayimg">
          <img :src="qrcode">
      </div>
</div>
</template>

<script>
    export default {
        name: "Pay",
        data(){
            return{
                userAmount:0,
                totalPrice: JSON.parse(sessionStorage.getItem("data")).totalPrice,
                userId:this.$store.getters.getUser.userId,
                wxpayimg:false,
                qrcode:''
            }
        },
        created(){
            this.queryUserAmount();
            //this.getWxpayimg();
        },
        methods:{
            queryUserAmount(){
                var vm=this;

                this.axios.get("http://localhost:8085/userWallet/queryUserAmount?userId="+vm.userId).then(function (res) {
                    vm.userAmount=res.data.data;
                })
            },
            alipay(){
                var vm=this;
                this.axios.get("http://localhost:8087/alipay/alipayOpen?totalPrice="+vm.totalPrice).then(function (res) {
                    if(res.data.code==0){
                        console.log(res.data.data);

                        document.querySelector("body").innerHTML=res.data.data
                        document.forms[0].submit();
                    }else {
                        vm.$message.error("支付失败，请联系管理员！");
                    }
                })
            }

        },
        mounted(){
            this.qrcode="http://localhost:8085/wxpay/xiadan.sjsp?totalPrice="+this.totalPrice;
            //创建全局GoEasy对象
           var goEasy = new GoEasy({
                host:'hangzhou.goeasy.io', //应用所在的区域地址: 【hangzhou.goeasy.io |singapore.goeasy.io】
                appkey: "BC-ca5c545611254593854db43b1b1692ee", //替换为您的应用appkey

            });
            //接受客户端推送过来的消息
            goEasy.subscribe({
                channel: "1911", //替换为您自己的channel
                onMessage: function (message) {
                    this.$message.success("支付成功！！")
                }
            });
        }

    }
</script>

<style scoped>

</style>
